import random

from django.utils import timezone

from apps.system.models import User
from extensions.models import *

from apps.common.models import PamBaseModel, PbiBaseCheck


class Pam_Progress_log(Model):
    """商机进展情况记录"""
    pam_business_opportunity = ForeignKey('pam.Pam_business_opportunity_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_business_opportunity_Progress_log')
    progress = CharField(max_length=255, verbose_name='进展情况', null=True, blank=True, help_text='进展情况')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL,null=True, blank=True, default=None,
                           related_name='Pam_business_opportunity_Progress_log')  # 填报人
    add_time = DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)


class Pam_business_opportunityCheck(PbiBaseCheck):
    pam_business_opportunity = ForeignKey('pam.Pam_business_opportunity_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_business_opportunityCheck')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_business_opportunityCheck')

    class Meta:
        verbose_name = 'Pam_business_opportunityCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

# 项目调账商机明细表
class Pam_business_opportunity_Records(PamBaseModel):

    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='Pam_business_opportunity_Records')
    # region = ForeignKey('system.Region', on_delete=CASCADE, blank=True, default=None,
    #                      related_name='Pam_business_opportunity_Records')
    region = JSONField(blank=True, default=None,verbose_name='区县')
    is_frame = BooleanField(verbose_name='是否框架', default=False)
    name_of_first_party = CharField(max_length=255, verbose_name='甲方名称', null=True, blank=True, help_text='甲方名称')
    collection_date = DateField(verbose_name='商机收集时间', null=True, blank=True)
    project_content = CharField(max_length=255, verbose_name='项目内容', null=True, blank=True, help_text='项目内容')
    construction_area = CharField(max_length=255, verbose_name='施工区域', null=True, blank=True, help_text='项目内容')
    sphere = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='圈层', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_sphere')
    attribute_of_first_party = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='甲方属性', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_attribute_of_first_party')
    field_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之领域', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_field_business_attribute')#通信专业-线路类,通信专业-无线类等
    classification_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之分类', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_classification_business_attribute')#新建、迁改等

    budget = FloatField(verbose_name='预算金额', null=True, blank=True, default=0)
    tax_rate = FloatField(verbose_name='税率', null=True, blank=True, default=0)
    success_rate_estimate = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='成功率', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_success_rate')#100%、80%等
    # project_source = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='项目来源', blank=True,
    #                                  default=None,related_name='Pam_business_opportunity_Records_project_source')#省分投标（纯自谈）等
    state = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='状态', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_state')#可研阶段等

    # pam_Progress_log = ManyToManyField(Pam_Progress_log, null=True, blank=True,
    #                                 related_name='Pam_business_opportunity_Records_pam_Progress_log')  # 进展情况
    result = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='结果', blank=True,
                                     default=None,related_name='Pam_business_opportunity_Records_result')#成功、失败等
    estimated_signing_date = DateField(verbose_name='预计签约年月', null=True, blank=True)
    person_in_charge = CharField(max_length=255, verbose_name='项目拓展负责人', null=True, blank=True, help_text='项目拓展负责人')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_business_opportunity_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_business_opportunity_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_business_opportunity_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


class Pam_Contract_tobesigned_Progress_log(Model):
    """商机进展情况记录"""
    pam_Contract_tobesigned = ForeignKey('pam.Pam_Contract_tobesigned_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_Contract_tobesigned_Progress_log')
    progress = CharField(max_length=255, verbose_name='进展情况', null=True, blank=True, help_text='进展情况')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL,null=True, blank=True, default=None,
                           related_name='Pam_Contract_tobesigned_Progress_log')  # 填报人
    add_time = DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)


class Pam_Contract_tobesignedCheck(PbiBaseCheck):
    pam_Contract_tobesigned = ForeignKey('pam.Pam_Contract_tobesigned_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_Contract_tobesignedCheck')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_Contract_tobesignedCheck')

    class Meta:
        verbose_name = 'Pam_Contract_tobesignedCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

#
class Pam_Contract_tobesigned_Records(PamBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='Pam_Contract_tobesigned_Records')
    # region = ForeignKey('system.Region', on_delete=CASCADE, blank=True, default=None,
    #                      related_name='Pam_Contract_tobesigned_Records')
    region = JSONField(blank=True, default=None,verbose_name='区县')
    is_frame = BooleanField(verbose_name='是否框架', default=False)
    name_of_first_party = CharField(max_length=255, verbose_name='甲方名称', null=True, blank=True, help_text='甲方名称')
    # collection_date = DateField(verbose_name='商机收集时间', null=True, blank=True)
    project_content = CharField(max_length=255, verbose_name='项目内容', null=True, blank=True, help_text='项目内容')
    construction_area = CharField(max_length=255, verbose_name='施工区域', null=True, blank=True, help_text='项目内容')
    sphere = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='圈层', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_sphere')
    attribute_of_first_party = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='甲方属性', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_attribute_of_first_party')
    field_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之领域', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_field_business_attribute')#通信专业-线路类,通信专业-无线类等
    classification_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之分类', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_classification_business_attribute')#新建、迁改等

    budget = FloatField(verbose_name='预算金额', null=True, blank=True, default=0)
    tax_rate = FloatField(verbose_name='税率', null=True, blank=True, default=0)
    project_source = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='项目来源', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_project_source')#省分投标（纯自谈）等
    result = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='结果', blank=True,
                                     default=None,related_name='Pam_Contract_tobesigned_Records_result')#成功、失败等
    estimated_signing_date = DateField(verbose_name='预计签约年月', null=True, blank=True)
    person_in_charge = CharField(max_length=255, verbose_name='项目拓展负责人', null=True, blank=True, help_text='项目拓展负责人')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_Contract_tobesigned_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_Contract_tobesigned_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_Contract_tobesigned_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


class Pam_contract_managementCheck(PbiBaseCheck):
    pam_contract_management = ForeignKey('pam.Pam_contract_management_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_contract_managementCheck')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_contract_managementCheck')

    class Meta:
        verbose_name = 'Pam_contract_managementCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

#
class Pam_contract_management_Records(PamBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='Pam_contract_management_Records')
    # region = ForeignKey('system.Region', on_delete=CASCADE, blank=True, default=None,
    #                      related_name='Pam_contract_management_Records')
    erp_number = CharField(max_length=255, unique=True, verbose_name='ERP合同编号', null=True, blank=True)
    region = JSONField(blank=True, default=None,verbose_name='区县')
    is_frame = BooleanField(verbose_name='是否框架', default=False)
    name_of_first_party = CharField(max_length=255, verbose_name='甲方名称', null=True, blank=True, help_text='合同对方')
    signing_date = DateField(verbose_name='签订时间', null=True, blank=True)
    expiry_date = DateField(verbose_name='合同截止日期', null=True, blank=True)
    sphere = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='圈层', blank=True,
                                     default=None,related_name='Pam_contract_management_Records_sphere')
    attribute_of_first_party = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='甲方属性', blank=True,
                                     default=None,related_name='Pam_contract_management_Records_attribute_of_first_party')
    field_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之领域', blank=True,
                                     default=None,related_name='Pam_contract_management_Records_field_business_attribute')#通信专业-线路类,通信专业-无线类等
    classification_business_attribute = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='业务属性之分类', blank=True,
                                     default=None,related_name='Pam_contract_management_Records_classification_business_attribute')#新建、迁改等

    contract_amount = FloatField(verbose_name='合同金额', null=True, blank=True, default=0)
    estimated_cash_amount = FloatField(verbose_name='预计兑现金额', null=True, blank=True, default=0)
    tax_rate = FloatField(verbose_name='税率', null=True, blank=True, default=0)
    project_source = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='项目来源', blank=True,
                                     default=None,related_name='Pam_contract_management_Records_project_source')#省分投标（纯自谈）等
    erp_contract_seal_date = DateField(verbose_name='ERP系统合同章用印时间', null=True, blank=True)
    estimated_cash_date = DateField(verbose_name='预计兑现年月', null=True, blank=True)
    person_liable = CharField(max_length=255, verbose_name='责任人', null=True, blank=True, help_text='责任人')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_contract_management_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_contract_management_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_contract_management_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


class Pam_framecontract_orderCheck(PbiBaseCheck):
    pam_framecontract_order = ForeignKey('pam.Pam_framecontract_order_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_framecontract_orderCheck')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_framecontract_orderCheck')

    class Meta:
        verbose_name = 'Pam_framecontract_orderCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

#
class Pam_framecontract_order_Records(PamBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='Pam_framecontract_order_Records')
    region = JSONField(null=True,blank=True, default=None, verbose_name='区县')
    pam_contract_management = ForeignKey('pam.Pam_contract_management_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_framecontract_order_Records')
    project_type = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='项目类型', blank=True,
                                     default=None,related_name='Pam_framecontract_order_Records_project_type')
    order_amount = FloatField(verbose_name='订单金额', null=True, blank=True, default=0)
    order_estimated_cash_amount = FloatField(verbose_name='预计兑现金额', null=True, blank=True, default=0)
    order_dispatch_date = DateField(verbose_name='订单派发时间', null=True, blank=True)
    order_estimated_cash_date = DateField(verbose_name='预计兑现年月', null=True, blank=True)
    tax_rate = FloatField(verbose_name='税率', null=True, blank=True, default=0)
    order_person_liable = CharField(max_length=255, verbose_name='责任人', null=True, blank=True, help_text='责任人')
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_framecontract_order_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_framecontract_order_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_framecontract_order_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


class Pam_framecontract_order_wholeCheck(PbiBaseCheck):
    pam_framecontract_order_whole = ForeignKey('pam.Pam_framecontract_order_whole_Records', on_delete=CASCADE, blank=True, default=None, related_name='pam_framecontract_order_whole')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_framecontract_order_wholeCheckcheck_user')

    class Meta:
        verbose_name = 'Pam_framecontract_order_wholeCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

#项目全流程管理数据台账-框架合同
class Pam_framecontract_order_whole_Records(PamBaseModel):
    pam_framecontract_order = ForeignKey('pam.Pam_framecontract_order_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_framecontract_order_whole_Records')
    project_manager = CharField(max_length=255, verbose_name='项目经理', null=True, blank=True, help_text='项目经理')
    # 预算情况
    income = FloatField(verbose_name='收入', null=True, blank=True, default=0)
    labor_cost = FloatField(verbose_name='人工费', null=True, blank=True, default=0)
    other_expenses = FloatField(verbose_name='其他费用', null=True, blank=True, default=0)
    # 施工组织模式
    construction_organization_mode = ForeignKey('system.Dict_item', null=True, on_delete=CASCADE, verbose_name='施工组织方式', blank=True,
                                     default=None,related_name='Pam_framecontract_order_whole_Records_construction_organization_mode')
    labor_subcontracting_mode = ForeignKey('system.Dict_item', null=True, on_delete=CASCADE, verbose_name='劳务分包方式', blank=True,
                                     default=None,related_name='Pam_framecontract_order_whole_Records_labor_subcontracting_mode')
    erp_service_contract_name = CharField(max_length=255, verbose_name='ERP劳务合同名称', null=True, blank=True, help_text='ERP劳务合同名称')
    labor_subcontractor = CharField(max_length=255, verbose_name='劳务分包单位', null=True, blank=True, help_text='劳务分包单位')
    dispatch_amount = FloatField(verbose_name='派单金额', null=True, blank=True, default=0)
    # 进度情况
    cumulative_sites = IntegerField(verbose_name='累计站点/段落/条数', null=True, blank=True, default=0)
    cumulative_ports = IntegerField(verbose_name='累计完工端口数（家宽项目）', null=True, blank=True, default=0)
    cumulative_completed_sites = IntegerField(verbose_name='累计完工站点/段落/条数', null=True, blank=True, default=0)
    cumulative_completed_ports = IntegerField(verbose_name='累计端口数（家宽项目）', null=True, blank=True, default=0)
    cumulative_acceptance_sites = IntegerField(verbose_name='累计甲方验收站点/段落/条数', null=True, blank=True, default=0)
    cumulative_acceptance_ports = IntegerField(verbose_name='累计甲方验收端口数（家宽项目）', null=True, blank=True, default=0)
    # 收入情况
    cumulative_completion_income = FloatField(verbose_name='累计完工工作量（不含税、元)', null=True, blank=True, default=0)
    cumulative_acceptance_income = FloatField(verbose_name='累计验收工作量（不含税、元）', null=True, blank=True, default=0)
    cumulative_invoicing_income = FloatField(verbose_name='累计财务确认开票收入（不含税、元）', null=True, blank=True, default=0)
    cumulative_estimated_income = FloatField(verbose_name='累计财务确认暂估收入（不含税、元）', null=True, blank=True, default=0)
    accumulated_receipts_income = FloatField(verbose_name='累计已收款（不含税、元）', null=True, blank=True, default=0)
    # 成本情况
    cumulative_invoicing_cost = FloatField(verbose_name='累计财务确认开票成本（不含税、元）', null=True, blank=True, default=0)
    cumulative_estimated_cost = FloatField(verbose_name='累计财务确认暂估成本（不含税、元）', null=True, blank=True, default=0)
    cumulative_labour_cost = FloatField(verbose_name='其中劳务成本（不含税、元）', null=True, blank=True, default=0)
    accumulated_pay_cost = FloatField(verbose_name='累计已付款（不含税、元）', null=True, blank=True, default=0)
    # 审计情况
    submitted_amount = FloatField(verbose_name='送审金额（不含税、元）', null=True, blank=True, default=0)
    approved_amount = FloatField(verbose_name='审定金额（不含税、元）', null=True, blank=True, default=0)
    # 订单执行情况
    order_execution = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='订单执行情况', blank=True,
                                     default=None,related_name='Pam_framecontract_order_whole_Records_order_execution')
    #填报信息
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_framecontract_order_whole_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_framecontract_order_whole_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_framecontract_order_whole_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.number


class Pam_singlecontract_order_wholeCheck(PbiBaseCheck):
    pam_singlecontract_order_whole = ForeignKey('pam.Pam_singlecontract_order_whole_Records', on_delete=CASCADE, blank=True, default=None, related_name='pam_singlecontract_order_whole')
    check_user = ForeignKey('system.User', on_delete=CASCADE, blank=True, default=None, related_name='Pam_singlecontract_order_wholeCheckcheck_user')

    class Meta:
        verbose_name = 'Pam_singlecontract_order_wholeCheck审核记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.opinion

#项目全流程管理数据台账-单项合同
class Pam_singlecontract_order_whole_Records(PamBaseModel):
    pam_contract_management = ForeignKey('pam.Pam_contract_management_Records', on_delete=CASCADE, blank=True, default=None, related_name='Pam_singlecontract_order_whole_Records')
    project_manager = CharField(max_length=255, verbose_name='项目经理', null=True, blank=True, help_text='项目经理')
    # 预算情况
    income = FloatField(verbose_name='收入', null=True, blank=True, default=0)
    labor_cost = FloatField(verbose_name='人工费', null=True, blank=True, default=0)
    other_expenses = FloatField(verbose_name='其他费用', null=True, blank=True, default=0)
    # 施工组织模式
    construction_organization_mode = ForeignKey('system.Dict_item', null=True, on_delete=CASCADE, verbose_name='施工组织方式', blank=True,
                                     default=None,related_name='Pam_singlecontract_order_whole_Records_construction_organization_mode')
    labor_subcontracting_mode = ForeignKey('system.Dict_item', null=True, on_delete=CASCADE, verbose_name='劳务分包方式', blank=True,
                                     default=None,related_name='Pam_singlecontract_order_whole_Records_labor_subcontracting_mode')
    erp_service_contract_name = CharField(max_length=255, verbose_name='ERP劳务合同名称', null=True, blank=True, help_text='ERP劳务合同名称')
    labor_subcontractor = CharField(max_length=255, verbose_name='劳务分包单位', null=True, blank=True, help_text='劳务分包单位')
    dispatch_amount = FloatField(verbose_name='派单金额', null=True, blank=True, default=0)
    # 进度情况
    cumulative_sites = IntegerField(verbose_name='累计站点/段落/条数', null=True, blank=True, default=0)
    cumulative_ports = IntegerField(verbose_name='累计完工端口数（家宽项目）', null=True, blank=True, default=0)
    cumulative_completed_sites = IntegerField(verbose_name='累计完工站点/段落/条数', null=True, blank=True, default=0)
    cumulative_completed_ports = IntegerField(verbose_name='累计端口数（家宽项目）', null=True, blank=True, default=0)
    cumulative_acceptance_sites = IntegerField(verbose_name='累计甲方验收站点/段落/条数', null=True, blank=True, default=0)
    cumulative_acceptance_ports = IntegerField(verbose_name='累计甲方验收端口数（家宽项目）', null=True, blank=True, default=0)
    # 收入情况
    cumulative_completion_income = FloatField(verbose_name='累计完工工作量（不含税、元)', null=True, blank=True, default=0)
    cumulative_acceptance_income = FloatField(verbose_name='累计验收工作量（不含税、元）', null=True, blank=True, default=0)
    cumulative_invoicing_income = FloatField(verbose_name='累计财务确认开票收入（不含税、元）', null=True, blank=True, default=0)
    cumulative_estimated_income = FloatField(verbose_name='累计财务确认暂估收入（不含税、元）', null=True, blank=True, default=0)
    accumulated_receipts_income = FloatField(verbose_name='累计已收款（不含税、元）', null=True, blank=True, default=0)
    # 成本情况
    cumulative_invoicing_cost = FloatField(verbose_name='累计财务确认开票成本（不含税、元）', null=True, blank=True, default=0)
    cumulative_estimated_cost = FloatField(verbose_name='累计财务确认暂估成本（不含税、元）', null=True, blank=True, default=0)
    cumulative_labour_cost = FloatField(verbose_name='其中劳务成本（不含税、元）', null=True, blank=True, default=0)
    accumulated_pay_cost = FloatField(verbose_name='累计已付款（不含税、元）', null=True, blank=True, default=0)
    # 审计情况
    submitted_amount = FloatField(verbose_name='送审金额（不含税、元）', null=True, blank=True, default=0)
    approved_amount = FloatField(verbose_name='审定金额（不含税、元）', null=True, blank=True, default=0)
    # 订单执行情况
    order_execution = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='订单执行情况', blank=True,
                                     default=None,related_name='Pam_singlecontract_order_whole_Records_order_execution')
    #填报信息
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_singlecontract_order_whole_Records_filled_by')  # 支填报人
    update_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Pam_singlecontract_order_whole_Records_update_by')  # 更新人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Pam_singlecontract_order_whole_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.number

# 供应商管理-供应商信息
class Pam_supplier_management_Records(Model):
    number = CharField(max_length=255, verbose_name='编号', null=True, blank=True, help_text='编号')
    # 资源库
    resource_pool = CharField(max_length=255, verbose_name='资源库', null=True, blank=True, help_text='资源库')
    supplier_name = CharField(max_length=255, verbose_name='供应商名称', null=True, blank=True, help_text='供应商名称')
    supplier_contact = CharField(max_length=255, verbose_name='供应商联系人', null=True, blank=True, help_text='供应商联系人')
    supplier_contact_phone = CharField(max_length=255, verbose_name='供应商联系人电话', null=True, blank=True, help_text='供应商联系人电话')
#     创建时间
    create_time = DateTimeField(verbose_name='创建时间', auto_now_add=True)
#     更新时间
    update_time = DateTimeField(verbose_name='更新时间', auto_now=True)
#     创建人
    create_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, verbose_name='用户',related_name='Pam_supplier_management_Records_create_by',db_constraint=False)
#     更新人
    update_by = ForeignKey(User, on_delete=SET_NULL, null=True, blank=True, verbose_name='用户',related_name='Pam_supplier_management_Records_update_by',db_constraint=False)

    def __str__(self):
        return self.number

# 自动生成唯一编号，时间戳+随机数
    def _generate_number(self):
        timestamp = timezone.now().strftime('%Y%m%d%H%M%S')
        random_digits = random.randint(10000, 99999)
        return 'S'+timestamp + str(random_digits)
